import {Card} from './Card';

export class Deck {

    private cards: Card[] = [];

    constructor() {
        this.reset();
    }

    // 重置牌堆
    reset() {
        this.cards = [];
        for (let i = 0; i < 52; i++) {
            this.cards.push(new Card(i));
        }
        this.shuffle();
    }

    // 洗牌
    shuffle() {
        for (let i = this.cards.length - 1; i > 0; i--) {
            const j = Math.floor(Math.random() * (i + 1));
            [this.cards[i], this.cards[j]] = [this.cards[j], this.cards[i]];
        }
    }

    // 发牌
    drawCard(): Card {
        return this.cards.pop()
    }
}